package main

import "fmt"

//二分法查找
//切片s是升序的
//k为待查找的整数
//如果查到有就返回对应角标,
//没有就返回-1

func search(nums []int, target int) int {
	var low = 0             //数组最小的下标
	var hig = len(nums) - 1 //数组最大的下标
	for low <= hig {
		var mid = (hig + low) / 2
		if nums[mid] == target {
			return mid
		} else if nums[mid] > target {
			hig = mid - 1
		} else if nums[mid] < target {
			low = mid + 1
		}
	}
	return -1
}

func main() {
	nums := []int{7, 13, 33, 87, 99, 97, 117, 123, 129, 131, 137}
	a := search(nums, 13)
	fmt.Println(a)
}
